package com.zk5_education;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class R{

    @ApiModelProperty(value="是否成功")
    private Boolean success;

    @ApiModelProperty(value="返回码")
    private Integer Code;


    @ApiModelProperty(value="返回信息")
    private String message;

    @ApiModelProperty(value="返回数据")
    private Map<String,Object>data=new HashMap<>();

//    构造器私有化
    private R(){}

//    链式编程
    public static R success(){
       R rm=new R();
        rm.setCode(ResultCode.SUCCESS);
        rm.setMessage("成功");
        rm.setSuccess(true);
        return rm;
    }
    public static R error(){
       R rm=new R();
        rm.setCode(ResultCode.ERROR);
        rm.setMessage("失败");
        rm.setSuccess(false);
        return rm;
    }
    public R data(Map<String,Object>map){
        this.setData(map);
        return this;
    }

    public R code(Integer code){
        this.setCode(code);
        return this;
    }

    public R message(String message){
        this.setMessage(message);
        return this;
    }

    public R success1(Boolean success){
        this.setSuccess(success);
        return this;
    }
    public R data(String key,Object value){
        this.data.put(key,value);
        return this;
    }


}
